package org.spring.springboot.app.adv.advscreeninfo.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spring.springboot.app.adv.advcombinfo.domain.po.AdvCombInfoPO;
import org.spring.springboot.app.adv.advcombinfo.service.IAdvCombInfoService;
import org.spring.springboot.app.adv.advexam.service.IAdvExamService;
import org.spring.springboot.app.adv.advinfo.dao.AdvInfoDao;
import org.spring.springboot.app.adv.advinfo.domain.po.AdvInfoPO;
import org.spring.springboot.app.adv.advscreeninfo.dao.AdvScreenInfoDao;
import org.spring.springboot.app.adv.advscreeninfo.dao.AdvScreenLogDao;
import org.spring.springboot.app.adv.advscreeninfo.domain.po.AdvScreenInfoPO;
import org.spring.springboot.app.adv.advscreeninfo.domain.vo.*;
import org.spring.springboot.app.adv.advscreeninfo.service.IAdvScreenInfoService;
import org.spring.springboot.app.base.Constants;
import org.spring.springboot.app.base.R;
import org.spring.springboot.app.base.User;
import org.spring.springboot.app.platform.balancelog.service.IPlatformBalanceLogService;
import org.spring.springboot.app.sys.office.domain.po.SysOfficePO;
import org.spring.springboot.app.sys.office.domain.po.SysOfficeWalletPO;
import org.spring.springboot.app.sys.office.service.ISysOfficeService;
import org.spring.springboot.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class AdvScreenInfoServiceImpl implements IAdvScreenInfoService {

    private static final Logger LOGGER = LoggerFactory.getLogger(AdvScreenInfoServiceImpl.class);

    @Autowired
    private AdvScreenInfoDao advScreenInfoDao;
    @Autowired
    private AdvScreenLogDao advScreenLogDao;
    @Autowired
    private AdvInfoDao advInfoDao;
    @Autowired
    private IAdvCombInfoService advCombInfoService;
    @Autowired
    private ISysOfficeService sysOfficeService;
    @Autowired
    private IAdvExamService advExamService;
    @Autowired
    private IPlatformBalanceLogService platformBalanceLogService;


    @Override
    public AdvScreenInfoPO find(String id) {
        return advScreenInfoDao.selectByPrimaryKey(id);
    }

    @Override
    public R delete(String id) {
        R r = new R();
        AdvInfoPO mainPo = new AdvInfoPO();
        mainPo.setId(id);
        mainPo.preDelete();
        if (advInfoDao.updateByPrimaryKeySelective(mainPo) == 0) {
            return r.fail().setMessage("保存失败");
        }
        AdvScreenInfoPO po = new AdvScreenInfoPO();
        po.setId(id);
        po.preDelete();
        if (advScreenInfoDao.updateByPrimaryKeySelective(po) == 0) {
            return r.fail().setMessage("保存失败");
        }
        return r.success();
    }



    @Override
    public List<AdvScreenInfoPO> findPageForMyPublic(AdvScreenInfoSearchVO searchVO, int pageNum, int pageSize) {
        return advScreenInfoDao.findPage(searchVO, pageNum,pageSize);
    }

    @Override
    @Transactional
    public R saveForMyPublic(AdvScreenInfoForMyPublicSaveInVO vo, User user) {
        R r = new R();
        AdvCombInfoPO combInfoPO = advCombInfoService.find(vo.getAdvCombId());
        if (combInfoPO == null) {
            return r.fail().setMessage("套餐错误");
        }
        //判断套餐是否自己的
        if (!user.getOfficeId().equals(combInfoPO.getOfficeId())) {
            return r.fail().setMessage("请选择您的套餐");
        }
        //检查套餐在此时间段内是否可以发布
        if(!checkCanPublish(vo.getAdvCombId(),vo.getReward(),vo.getStartDate_(),vo.getEndDate_())){
            return r.fail().setMessage("该时间段内的广告位已满");
        }
        int hardCount = advCombInfoService.queryHardCount(combInfoPO.getId());
        double eachPlatform = 0;
        double eachCommision = 0;
        int alldays = vo.getZoneDay();
        int reward =  vo.getReward();
        switch (reward) {
            case Constants.ADV_SCREEN_INFO_REWARD_1: {//轮播
                eachPlatform = 0.1;//平台服务费
                eachCommision = 0;//自己发不要佣金
            }
            break;
            case Constants.ADV_SCREEN_INFO_REWARD_2: {//精准
                eachPlatform = 0.2;//平台服务费
                eachCommision = 0;//自己发不要佣金
            }
            break;
            default:{
                return r.fail().setMessage("投放类型不正确");
            }
        }
        BigDecimal eachPlatformMo= new BigDecimal(eachPlatform);
        BigDecimal allPlatformMo= eachPlatformMo.multiply(new BigDecimal(hardCount)).multiply(new BigDecimal(alldays));
        BigDecimal eachCommisionMo= new BigDecimal(eachCommision);
        BigDecimal allCommisionMo= eachCommisionMo.multiply(new BigDecimal(hardCount)).multiply(new BigDecimal(alldays));

        BigDecimal payMo = allPlatformMo.add(allCommisionMo);
        //保存主表
        AdvInfoPO mainPO = new AdvInfoPO();
        mainPO.setOfficeId(user.getOfficeId());
        mainPO.setType(Constants.ADV_INFO_TYPE_3);
        mainPO.setIsSystem(0);
        mainPO.setTitle(vo.getTitle());
        mainPO.setPhotos(vo.getPhotos());
        mainPO.setStartDate(vo.getStartDate_());
        mainPO.setEndDate(vo.getEndDate_());
        mainPO.setPayState(Constants.ADV_INFO_TYPE_PAY_STATE_1);
        mainPO.setPayMo(payMo);
        mainPO.setContent(vo.getContent());
        mainPO.preInsert();
        if (advInfoDao.insertSelective(mainPO) <1) {
            throw new RuntimeException("保存活动主表失败");
        }
        //保存副表
        AdvScreenInfoPO screenInfoPO = new AdvScreenInfoPO();
        screenInfoPO.setAdvCombId(combInfoPO.getId());
        screenInfoPO.setBuyOfficeId(combInfoPO.getOfficeId());
        screenInfoPO.setReward(vo.getReward());
        screenInfoPO.setBuyCycle(0);
        screenInfoPO.setEachCycleDays(0);
        screenInfoPO.setAllDays(alldays);
        screenInfoPO.setAllHardNum(hardCount);
        screenInfoPO.setEachPlatformMo(eachPlatformMo);
        screenInfoPO.setAllPlatformMo(allPlatformMo);
        screenInfoPO.setEachCommisionMo(eachCommisionMo);
        screenInfoPO.setAllCommisionMo(allCommisionMo);
        screenInfoPO.setSex(vo.getSex());
        screenInfoPO.setMinAge(vo.getMinAge());
        screenInfoPO.setMaxAge(vo.getMaxAge());
        screenInfoPO.setState(Constants.ADV_SCREEN_INFO_STATE_0);
        screenInfoPO.setVoice(vo.getVoice());
        screenInfoPO.setViewCount(0);
        screenInfoPO.preInsert();
        screenInfoPO.setId(mainPO.getId());
        if (advScreenInfoDao.insertSelective(screenInfoPO) <1) {
            throw new RuntimeException("保存活动副表失败");
        }

        AdvScreenInfoForMyPublicSaveOutVO outVO = new AdvScreenInfoForMyPublicSaveOutVO();
        outVO.setId(mainPO.getId());
        outVO.setPayMo(mainPO.getPayMo());
        return r.success().setData(outVO);
    }

    private boolean checkCanPublish(String advCombId,int reward, Date startDate, Date endDate) {
        //查询此套餐所有的广告
        AdvCombInfoPO combInfoPO = advCombInfoService.find(advCombId);
        int rewardNum = 0;
        switch (reward) {
            case Constants.ADV_SCREEN_INFO_REWARD_1: {//轮播
                rewardNum = combInfoPO.getPollingNum();
            }
            break;
            case Constants.ADV_SCREEN_INFO_REWARD_2: {//精准
                rewardNum = combInfoPO.getPreciseNum();
            }
            break;
        }
        if (rewardNum <= 0) {
            return false;
        }
        //通过套餐和投放类型查询所有的广告
        List<AdvScreenInfoPO>  allList = advScreenInfoDao.queryListByComb(advCombId,reward);
        //没有广告或者广告位不足则直接返回成功
        if (allList == null || allList.size() < rewardNum) {
            return true;
        }
        //超过数量的广告需要计算时间是否匹配
        return isTimeOk(allList,rewardNum,startDate,endDate);
    }

    private boolean isTimeOk(List<AdvScreenInfoPO> allList, int rewardNum, Date startDate, Date endDate) {
        List<Integer> timeArr = new ArrayList<Integer>();
        for (AdvScreenInfoPO po : allList) {
            //将所有时间变成以2000年为基数的整数
            int start = DateUtil.daysFrom2000(po.getStartDate());
            int end = DateUtil.daysFrom2000(po.getEndDate());
            for (int i = start; i <= end; i++) {
                timeArr.add(i);
            }
        }
        int _start = DateUtil.daysFrom2000(startDate);
        int _end = DateUtil.daysFrom2000(endDate);
        List<Integer> _timeArr = new ArrayList<Integer>();
        for (int j = _start; j <= _end; j++) {
            _timeArr.add(j);
        }
        if (_timeArr.size() > 0 && timeArr.size() > 0) {
            for (Integer a : _timeArr) {
                int count = 0;
                for (Integer b : timeArr) {
                    if (a.intValue() == b.intValue()) {
                        count++;
                    }
                }
                if (count >= rewardNum) {
                    return false;
                }
            }
        }
        return true;
    }


    @Override
    public R updateInfo(AdvScreenInfoUpdateInVO vo) {
        R r = new R();
        //判断广告是否审核（审核之前可以修改）
        AdvScreenInfoPO screenInfoPO = advScreenInfoDao.selectByPrimaryKey(vo.getId());
        if (screenInfoPO.getExamState() != null && screenInfoPO.getExamState().intValue() == Constants.ADV_EXAM_STATE_2) {
            return r.fail().setMessage("已审核广告不能修改");
        }

        //保存主表
        AdvInfoPO mainPo = new AdvInfoPO();
        mainPo.setId(vo.getId());
        mainPo.setTitle(vo.getTitle());
        mainPo.setContent(vo.getContent());
        mainPo.setPhotos(vo.getPhotos());
        mainPo.preUpdate();
        if (advInfoDao.updateByPrimaryKeySelective(mainPo) <1) {
            return r.fail().setMessage("修改活动主表失败");
        }
        if (StringUtils.isNotBlank(vo.getVoice())) {
            AdvScreenInfoPO screenInfoPO1 = new AdvScreenInfoPO();
            screenInfoPO1.setId(vo.getId());
            screenInfoPO1.setVoice(vo.getVoice());
            screenInfoPO1.preUpdate();
            if (advScreenInfoDao.updateByPrimaryKeySelective(screenInfoPO1) <1) {
                return r.fail().setMessage("修改活动副表失败");
            }
        }
        return r.success();
    }



    @Override
    @Transactional
    public R pay(String id, User user) {
        R r = new R();
        AdvInfoPO mainPO = advInfoDao.selectByPrimaryKey(id);
        //判断支付状态
        if (mainPO.getPayState().intValue() == Constants.ADV_INFO_TYPE_PAY_STATE_2) {
            return r.fail().setMessage("活动已经支付");
        }
        //比对机构金额和广告费用
        SysOfficeWalletPO walletPO = sysOfficeService.queryWallet(user.getOfficeId());
        BigDecimal balance = walletPO.getBalance();
        BigDecimal payMo = mainPO.getPayMo();
        if (payMo.compareTo(balance) > 0) {
            return  r.fail().setMessage("余额不足");
        }
        //扣除机构费用
        sysOfficeService.subOfficeMo(user.getOfficeId(),payMo,Constants.SYS_OFFICE_BALANCE_LOG_TYPE_102,id,null,mainPO.getTitle());
        //添加审核表
        advExamService.addExam(user.getOfficeId(),id);
        //修改广告状态
        mainPO.setPayState(Constants.ADV_INFO_TYPE_PAY_STATE_2);
        mainPO.preUpdate();
        if (advInfoDao.updateByPrimaryKeySelective(mainPO) < 1) {
            throw new RuntimeException("更新活动主表失败");
        }
        return r.success();
    }

    @Override
    public R saveForMyAskFor(AdvScreenInfoForMyAskForSaveInVO vo, User user) {
        R r = new R();
        AdvCombInfoPO combInfoPO = advCombInfoService.find(vo.getAdvCombId());
        if (combInfoPO == null) {
            return r.fail().setMessage("套餐错误");
        }
        //判断套餐是否自己的
        if (user.getOfficeId().equals(combInfoPO.getOfficeId())) {
            return r.fail().setMessage("请选择对方的套餐");
        }
        int hardCount = advCombInfoService.queryHardCount(combInfoPO.getId());
        double eachPlatform = 0;
        double eachCommision = 0;
        int alldays = combInfoPO.getDays() * vo.getBuyCycle();
        int reward =  vo.getReward();
        switch (reward) {
            case Constants.ADV_SCREEN_INFO_REWARD_1: {//轮播
                eachPlatform = 0.1;//平台服务费
                eachCommision =  combInfoPO.getTurnPrice().doubleValue();//轮播佣金
            }
            break;
            case Constants.ADV_SCREEN_INFO_REWARD_2: {//精准
                eachPlatform = 0.2;//平台服务费
                eachCommision = combInfoPO.getAccuratePrice().doubleValue();//精准佣金
            }
            break;
            default:{
                return r.fail().setMessage("投放类型不正确");
            }
        }
        BigDecimal eachPlatformMo= new BigDecimal(eachPlatform);
        BigDecimal allPlatformMo= eachPlatformMo.multiply(new BigDecimal(hardCount)).multiply(new BigDecimal(alldays));
        BigDecimal eachCommisionMo= new BigDecimal(eachCommision);
        BigDecimal allCommisionMo= eachCommisionMo.multiply(new BigDecimal(hardCount)).multiply(new BigDecimal(alldays));

        BigDecimal payMo = allPlatformMo.add(allCommisionMo);
        //保存主表
        AdvInfoPO mainPO = new AdvInfoPO();
        mainPO.setOfficeId(user.getOfficeId());
        mainPO.setType(Constants.ADV_INFO_TYPE_3);
        mainPO.setIsSystem(0);
        mainPO.setTitle(vo.getTitle());
        mainPO.setPhotos(vo.getPhotos());
        mainPO.setPayState(Constants.ADV_INFO_TYPE_PAY_STATE_1);
        mainPO.setPayMo(payMo);
        mainPO.setContent(vo.getContent());
        mainPO.preInsert();
        if (advInfoDao.insertSelective(mainPO) <1) {
            throw new RuntimeException("保存活动主表失败");
        }
        //保存副表
        AdvScreenInfoPO screenInfoPO = new AdvScreenInfoPO();
        screenInfoPO.setAdvCombId(combInfoPO.getId());
        screenInfoPO.setBuyOfficeId(combInfoPO.getOfficeId());
        screenInfoPO.setReward(vo.getReward());
        screenInfoPO.setBuyCycle(vo.getBuyCycle());
        screenInfoPO.setEachCycleDays(combInfoPO.getDays());
        screenInfoPO.setAllDays(alldays);
        screenInfoPO.setAllHardNum(hardCount);
        screenInfoPO.setEachPlatformMo(eachPlatformMo);
        screenInfoPO.setAllPlatformMo(allPlatformMo);
        screenInfoPO.setEachCommisionMo(eachCommisionMo);
        screenInfoPO.setAllCommisionMo(allCommisionMo);
        screenInfoPO.setSex(vo.getSex());
        screenInfoPO.setMinAge(vo.getMinAge());
        screenInfoPO.setMaxAge(vo.getMaxAge());
        screenInfoPO.setState(Constants.ADV_SCREEN_INFO_STATE_0);
        screenInfoPO.setVoice(vo.getVoice());
        screenInfoPO.setViewCount(0);
        screenInfoPO.preInsert();
        screenInfoPO.setId(mainPO.getId());
        if (advScreenInfoDao.insertSelective(screenInfoPO) <1) {
            throw new RuntimeException("保存活动副表失败");
        }

        AdvScreenInfoForMyPublicSaveOutVO outVO = new AdvScreenInfoForMyPublicSaveOutVO();
        outVO.setId(mainPO.getId());
        outVO.setPayMo(mainPO.getPayMo());
        return r.success().setData(outVO);
    }

    @Override
    public R updateForMyExam(AdvScreenInfoForMyExamUpdateInVO vo, User user) {
        R r = new R();
        AdvScreenInfoPO screenInfoPO = advScreenInfoDao.selectByPrimaryKey(vo.getId());
        if (screenInfoPO.getState().intValue() != Constants.ADV_SCREEN_INFO_STATE_1) {
            return r.fail().setMessage("不是待审核状态，不能操作");
        }
        boolean profitDicvision = false;
        if (vo.getState().intValue() == Constants.ADV_SCREEN_INFO_STATE_2) {//同意
            //检查套餐在此时间段内是否可以发布
            if(!checkCanPublish(screenInfoPO.getAdvCombId(),screenInfoPO.getReward(),vo.getStartDate_(),vo.getEndDate_())){
                return r.fail().setMessage("该时间段内的广告位已满");
            }
            AdvInfoPO mainPo = new AdvInfoPO();
            vo.setEndDate(DateUtil.zoneEndDate(vo.getStartDate_(),screenInfoPO.getAllDays()));
            mainPo.setStartDate(vo.getStartDate_());
            mainPo.setEndDate(vo.getEndDate_());
            mainPo.setId(vo.getId());
            mainPo.preUpdate();
            if (advInfoDao.updateByPrimaryKeySelective(mainPo) < 1) {
                throw new RuntimeException("更新活动主表失败");
            }
            profitDicvision = true;
        } else if (vo.getState().intValue() == Constants.ADV_EXAM_STATE_3) {//拒绝
        } else {
            return r.fail().setMessage("请传入正确的状态");
        }
        //更新审核状态
        screenInfoPO.setState(vo.getState());
        screenInfoPO.setRemarks(vo.getRemarks());
        screenInfoPO.preUpdate();
        if (advScreenInfoDao.updateByPrimaryKeySelective(screenInfoPO) < 1) {
            throw new RuntimeException("更新活动副表失败");
        }
        if (profitDicvision) {
            //分钱
            this.profitDivision(vo.getId());
        }
        return r.success();
    }

    @Override
    public R saveForSystem(AdvScreenInfoForSystemSaveInVO vo, User user) {
        R r = new R();
        //保存主表
        AdvInfoPO mainPO = new AdvInfoPO();
        mainPO.setOfficeId(user.getOfficeId());
        mainPO.setType(Constants.ADV_INFO_TYPE_3);
        mainPO.setIsSystem(1);
        mainPO.setTitle(vo.getTitle());
        mainPO.setPhotos(vo.getPhotos());
        mainPO.setStartDate(vo.getStartDate_());
        mainPO.setEndDate(vo.getEndDate_());
        mainPO.setPayState(Constants.ADV_INFO_TYPE_PAY_STATE_0);
        mainPO.setPayMo(null);
        mainPO.setContent(vo.getContent());
        mainPO.preInsert();
        if (advInfoDao.insertSelective(mainPO) <1) {
            throw new RuntimeException("保存活动主表失败");
        }
        //保存副表
        AdvScreenInfoPO screenInfoPO = new AdvScreenInfoPO();
        screenInfoPO.setAdvCombId(null);
        screenInfoPO.setBuyOfficeId(null);
        screenInfoPO.setReward(vo.getReward());
        screenInfoPO.setBuyCycle(0);
        screenInfoPO.setEachCycleDays(0);
        screenInfoPO.setAllDays(0);
        screenInfoPO.setAllHardNum(0);
        screenInfoPO.setEachPlatformMo(null);
        screenInfoPO.setAllPlatformMo(null);
        screenInfoPO.setEachCommisionMo(null);
        screenInfoPO.setAllCommisionMo(null);
        screenInfoPO.setSex(vo.getSex());
        screenInfoPO.setMinAge(vo.getMinAge());
        screenInfoPO.setMaxAge(vo.getMaxAge());
        screenInfoPO.setState(Constants.ADV_SCREEN_INFO_STATE_0);
        screenInfoPO.setVoice(vo.getVoice());
        screenInfoPO.setViewCount(0);
        screenInfoPO.preInsert();
        screenInfoPO.setId(mainPO.getId());
        if (advScreenInfoDao.insertSelective(screenInfoPO) <1) {
            throw new RuntimeException("保存活动副表失败");
        }
        return r.success();
    }

    @Override
    public int update(AdvScreenInfoPO po) {
        po.preUpdate();
        return advScreenInfoDao.updateByPrimaryKeySelective(po);
    }

    @Override
    public int profitDivision(String advId) {
        AdvScreenInfoPO po = advScreenInfoDao.selectByPrimaryKey(advId);
        AdvInfoPO mainPO = advInfoDao.selectByPrimaryKey(advId);
        if (po == null || po.getIsProfit() == 1) {
            return 0;
        }
        po.setIsProfit(1);
        po.preUpdate();
        if (advScreenInfoDao.updateByPrimaryKeySelective(po) < 1) {
            throw new RuntimeException("更新活动副表失败");
        }
        BigDecimal eachPlatformMo = po.getEachPlatformMo();
        BigDecimal allPlatformMo = po.getAllPlatformMo();
        BigDecimal eachCommisionMo = po.getEachCommisionMo();
        BigDecimal allCommisionMo = po.getAllCommisionMo();

        //平台服务费
        if (allPlatformMo.compareTo(BigDecimal.ZERO) == 1) {
            platformBalanceLogService.addBalanceLog(allCommisionMo,Constants.PLATFORM_BALANCE_LOG_TYPE_101,advId,null,mainPO.getTitle());
        }
        //划分佣金 设备拥有者80% 区域总代10% 设备拥有者的介绍者10%  剩下钱归平台
        if (allCommisionMo.compareTo(BigDecimal.ZERO) == 1) {
            BigDecimal lessMo = allCommisionMo;
            SysOfficePO ownerAgent = null;
            if (StringUtils.isNotBlank(po.getBuyOfficeId())) {
                ownerAgent = sysOfficeService.find(po.getBuyOfficeId());
                if (ownerAgent != null) {
                    BigDecimal mo = allCommisionMo.multiply(new BigDecimal(0.8)).setScale(3,BigDecimal.ROUND_DOWN);
                    lessMo = lessMo.subtract(mo);
                    sysOfficeService.addOfficeMo(ownerAgent.getId(),mo,Constants.SYS_OFFICE_BALANCE_LOG_TYPE_105,advId,null,mainPO.getTitle());
                }
            }
            SysOfficePO areaGeneralAgent = null;
            if (StringUtils.isNotBlank(po.getBuyOfficeId())) {
                areaGeneralAgent = sysOfficeService.queryAreaGeneralAgent(ownerAgent.getAreaId());
                if (areaGeneralAgent != null) {
                    BigDecimal mo = allCommisionMo.multiply(new BigDecimal(0.1)).setScale(3,BigDecimal.ROUND_DOWN);
                    lessMo = lessMo.subtract(mo);
                    sysOfficeService.addOfficeMo(areaGeneralAgent.getId(),mo,Constants.SYS_OFFICE_BALANCE_LOG_TYPE_105,advId,null,mainPO.getTitle());
                }
            }
            SysOfficePO introduceOffice = null;
            if (StringUtils.isNotBlank(ownerAgent.getIntroducer())) {
                introduceOffice = sysOfficeService.find(ownerAgent.getIntroducer());
                if (introduceOffice != null) {
                    BigDecimal mo = allCommisionMo.multiply(new BigDecimal(0.1)).setScale(3,BigDecimal.ROUND_DOWN);
                    lessMo = lessMo.subtract(mo);
                    sysOfficeService.addOfficeMo(introduceOffice.getId(),mo,Constants.SYS_OFFICE_BALANCE_LOG_TYPE_105,advId,null,mainPO.getTitle());
                }
            }
            //剩下的归平台
            if (lessMo.compareTo(BigDecimal.ZERO) == 1) {
                platformBalanceLogService.addBalanceLog(allCommisionMo,Constants.PLATFORM_BALANCE_LOG_TYPE_103,advId,null,mainPO.getTitle());
            }
        }
        return 1;
    }



    @Override
    public List<AdvScreenLogVO> findPageForMyPublicLog(AdvScreenLogSearchVO searchVO, int pageNum, int pageSize) {
        return advScreenLogDao.findPage(searchVO, pageNum,pageSize);
    }

}
